package com.niiwoo.civet.trade.report.ifcert.niwo.reports;

import com.alibaba.dubbo.config.annotation.Reference;
import com.niiwoo.civet.account.dto.response.AccountCompanyDTO;
import com.niiwoo.civet.account.service.AccountCompanyDubboService;
import com.niiwoo.civet.trade.dao.mapper.ProjectMapperExt;
import com.niiwoo.civet.trade.property.IfcertProperties;
import com.niiwoo.civet.trade.report.ifcert.niwo.ReportEvents;
import com.niiwoo.civet.trade.report.ifcert.niwo.ReporterAdapter;
import com.niiwoo.civet.trade.report.ifcert.niwo.SendClient;
import com.niiwoo.civet.user.service.UserBasicInfoDubboService;
import com.niiwoo.tripod.base.component.PrivacyMasks;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户信息
 * 是指出借人、借款人、第三方担保公司、平台自身、受托支付方的相关属性信息。
 */
@Service
@Slf4j
public class UserInfoReportor extends ReporterAdapter {
    @Autowired
    private SendClient sendClient;

    @Autowired
    private ProjectMapperExt projectMapperExt;

    @Reference
    private UserBasicInfoDubboService userBasicInfoDubboService;

    @Reference
    private AccountCompanyDubboService accountCompanyDubboService;

    @Autowired
    private PrivacyMasks privacyMasks;

    public UserInfoReportor(){
        this.supportEvents = ReportEvents.USER_INFO;
    }
    @Override
    protected void doReport(List<Long> projectIds, IfcertProperties ifcertProperties)  {
//
//        Set<UserInfoData> dataList = new HashSet<>();
//        for (Long projectId : projectIds) {
//            Project project  = projectMapperExt.selectByPrimaryKey(projectId);
//            UserBasicInfoResponseDTO basicInfo = userBasicInfoDubboService.getUserBasicInfo(project.getBorrowUserId());
//            UserInfoData user = new UserInfoData();
//            user.setVersion(ifcertProperties.getVersion());
//            user.setSourceCode(ifcertProperties.getSourceCode());
//            user.setUserType(project.getBorrowerType().toString());
//            /**
//             * 1-出借方／2-借款方／3-
//             * 出借方＋借款方/4-自代偿
//             * 平台方/5-第三方代偿/6-
//             * 受托支付方
//             */
//            user.setUserAttr("2");
//            user.setUserCreateTime(DateUtils.format(basicInfo.getCreateTime(),DateUtils.SHOW_DATETIME_FORMAT));
//            user.setUserName(project.getBorrowUserName());
//            user.setCountries("中国大陆");
//            user.setCardType("1");//身份证
//            String idcard = privacyMasks.decryptPrivacy(project.getBorrowIdCard());
//            user.setUserIdcard(idcard.substring(0,idcard.length()-4)+"****");
//            user.setUserIdcardHash(tool.idCardHash(idcard));
//
//            String mobile = privacyMasks.decryptPrivacy(project.getBorrowMobile());
//            user.setUserPhone(mobile.substring(0,mobile.length()-4)+"****");
//            Map<String, String> phoneAndSalt = this.getPhoneAndSalt(mobile);
//            user.setUserPhoneHash(phoneAndSalt.get(PHONEHASH));
//            user.setUserUuid(phoneAndSalt.get(USERUUID));
//            user.setUserLawperson(project.getBorrowerType().equals(Byte.valueOf("1"))? "-1":"");//todo
//            //user.set
//        }
//


    }

    public AccountCompanyDTO getCompanyInfo(String orgUserId){
       return accountCompanyDubboService.queryAccountCompanyByUserId(orgUserId);
    }


    @lombok.Data
    static class UserInfoData{
        private String version;
        private String sourceCode;
        private String userType;
        private String userAttr;
        private String userCreateTime;
        private String userName;
        private String countries;
        private String cardType;
        private String userIdcard;
        private String userIdcardHash;
        private String userPhone;
        private String userPhoneHash;
        private String userUuid;
        private String userLawperson;
        private String userFund;
        private String userProvince;
        private String registerDate;
        private String userSex;
        private String userBankAccount;

        public boolean equals(Object object){
            if (object instanceof UserInfoData){
                UserInfoData objectData = (UserInfoData) object;
                return objectData.userUuid.equalsIgnoreCase(this.getUserUuid());
            }else {
                return false;
            }
        }
        public int hashCode(){
            return this.getUserUuid().hashCode();
        }
    }
}
